package com.znjb.myapplication;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;


/**
 * Created by lx on 2016/6/18.
 */
public class MainPagerAdapter extends FragmentPagerAdapter {
    List<String> datas;
    List<Fragment> fragments;

    public MainPagerAdapter(FragmentManager fm, List<String> datas, List<Fragment> fragments) {
        super(fm);
        this.datas = datas;
        this.fragments = fragments;
    }

    public MainPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setDatas(List<String> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    /**
     * 返回每一页需要的Fragment
     * @param position
     * @return
     */
    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    /**
     * 返回Fragment的个数
     * @return
     */
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    /**
     * 返回Fragment的标题
      * @param position
     * @return
     */
    @Override
    public CharSequence getPageTitle(int position) {
        return datas.get(position);
    }
}
